<template>
  <div class="app-container">
    <el-dialog title="修改刮刮卡信息" :visible.sync="dialogconUp" center="true" @close="close">
      <el-form :model="accuseitem" :rules="rules" ref="presentlist" label-width="120px" class="demo-presentlist">
        <el-form-item label="归属点" prop="acptsiteid">
          <el-select v-model="accuseitem.acptsiteid" placeholder="请选择">
            <el-option label="a营业厅" value="36"></el-option>
            <el-option label="飞黄腾达" value="43"></el-option>
            <el-option label="望子成龙" value="44"></el-option>
            <el-option label="春天来了" value="45"></el-option>
            <el-option label="深夜留京紫" value="46"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="奖品等级" prop="prizelevel">
          <el-select v-model="accuseitem.prizelevel" placeholder="请选择">
            <el-option label="一等奖" value="1"></el-option>
            <el-option label="二等奖" value="2"></el-option>
            <el-option label="三等奖" value="3"></el-option>
            <el-option label="四等奖" value="4"></el-option>
            <el-option label="五等奖" value="5"></el-option>
            <el-option label="六等奖" value="6"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="卡状态" prop="state">
          <el-select v-model="accuseitem.state" placeholder="请选择">
            <el-option label="未领取" value="00"></el-option>
            <el-option label="已领取" value="10"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item style="margin-top: 20px">
          <el-button type="primary" @click="submitForm('presentlist')">修改</el-button>
          <el-button @click="resetForm('presentlist')">重置</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
import scratch from "@/api/scratch";
export default {
  props: {
    dialogconUpdate: {
      type: Boolean,
      default: false
    },
    accuseitem: {
      acptsiteid: '',//归属点
      prizelevel: '',//礼品等级
      state: '',//卡状态
    }
  },
  data() {
    return {
      dialogconUp: false,
      dialogImageUrl: '',
      presentlist: {
        cardno:null,//卡序列号
        acptsiteid: '',//归属点
        prizelevel: '',//礼品等级
        state: '',//卡状态
      },
      rules: {
        acptsiteid: [
          {required: true, message: '请选择归属点', trigger: 'blur'},
        ],
        prizelevel: [
          {required: true, message: '请选择礼品等级', trigger: 'blur'},
        ],
        state: [
          {required: true, message: '请选择卡状态', trigger: 'change'},
        ],
      }
    };
  },
  methods: {
    close() {
      this.$emit("update:dialogconUpdate", false)
    },
    submitForm(formName) {
      // alert(presentlist.cardno,presentlist.acptsiteid,presentlist.olddept,presentlist.prizelevel,presentlist.state)
      this.$refs[formName].validate((valid) => {
        this.presentlist = this.accuseitem;
        console.log(this.presentlist)
        scratch.updinfo(this.presentlist).then(res => {
          console.log(res)
          if (res.data == true) {
            this.$message({
              type: 'success',
              message: '修改成功!',
            });
          } else {
            this.$message({
              type: 'defeated',
              message: '修改失败!',
            });
          }
        })
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  },
  watch: {
    dialogconUpdate: {
      handler(newValue, oldValue) {
        this.dialogconUp = newValue;
        console.log(newValue, oldValue);
      }
    }
  }
}
</script>
